package com.pioneer.cloudstorage.config;

import com.pioneer.cloudstorage.interceptor.JwtTokenUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 配置类，注册web层相关组件
 */
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {


    @Autowired
    private JwtTokenUserInterceptor jwtTokenUserInterceptor;

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        //addInterceptor()方法参数是一个自定义的拦截器
        log.info("开始注册自定义拦截器...");
       /* 用于拦截 /user//** 路径下的请求，但排除 /user/user/login 接口。
     作用是对接口进行 JWT 登录验证，保障管理端接口安全。*/
        registry.addInterceptor(jwtTokenUserInterceptor)
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/auth/register")
                .excludePathPatterns("/api/auth/login")
                .excludePathPatterns("/api/shares/{shareId}/download")
                .excludePathPatterns("/api/shares/{shareId}");
    }




}
